<nz-card class="m-b-2">
  <div class="common-search-wrap">
    <div class="common-search-forms">
      <div class="common-form-item">
        <label class="common-search-label">所属品牌</label>
        <div class="common-search-conrol">
          <nz-select
            [(ngModel)]="seachParams.brandId"
            (nzScrollToBottom)="loadMore(0)"
            nzPlaceHolder="请选择所属品牌"
            nzAllowClear
            nzShowSearch
            [nzDropdownRender]="renderTemplate"
            (ngModelChange)="seachBrandChange($event)"
          >
            <nz-option *ngFor="let option of brandOptions" [nzValue]="option.id" [nzLabel]="option.name"></nz-option>
          </nz-select>
          <ng-template #renderTemplate>
            <nz-spin *ngIf="baradListForm.isLoading"></nz-spin>
          </ng-template>
        </div>
      </div>

      <div class="common-form-item">
        <label class="common-search-label">所属品类</label>
        <div class="common-search-conrol">
          <nz-select
            [(ngModel)]="seachParams.category"
            nzPlaceHolder="请选择所属品类"
            nzAllowClear
          >
            <nz-option [nzValue]="1" nzLabel="手机"></nz-option>
            <nz-option [nzValue]="2" nzLabel="平板"></nz-option>
          </nz-select>
        </div>
      </div>

      <div class="common-form-item">
        <label class="common-search-label">系列名称</label>
        <div class="common-search-conrol">
          <nz-select
            [(ngModel)]="seachParams.seriesId"
            (nzScrollToBottom)="loadMore(1)"
            nzPlaceHolder="请选择所属系列"
            nzAllowClear
            nzShowSearch
            [nzDropdownRender]="renderTemplate"
            (ngModelChange)="seriesChange($event)"
          >
            <nz-option *ngFor="let option of seriesOptions" [nzValue]="option.id" [nzLabel]="option.name"></nz-option>
          </nz-select>
          <ng-template #renderTemplate>
            <nz-spin *ngIf="seriesListForm.isLoading"></nz-spin>
          </ng-template>
        </div>
      </div>

      <div class="common-form-item">
        <label class="common-search-label">机型名称</label>
        <div class="common-search-conrol">
          <!-- <input nz-input placeholder="请输入机型名称" [(ngModel)]="seachParams.name" /> -->
          <nz-select
            nzShowSearch
            nzServerSearch
            nzAllowClear
            nzPlaceHolder="请输入机型名称"
            [(ngModel)]="seachParams.name"
            [nzFilterOption]="nzFilterOption"
            (nzOnSearch)="orderCodeSearch($event)"
          >
            <ng-container *ngFor="let o of orderCodeOptions">
              <nz-option *ngIf="!isOrderCodeLoading" [nzLabel]="o.name" [nzValue]="o.name"></nz-option>
            </ng-container>
            <nz-option *ngIf="isOrderCodeLoading" nzDisabled nzCustomContent>
              <i nz-icon nzType="loading" class="loading-icon"></i>
              Loading Data...
            </nz-option>
          </nz-select>
        </div>
      </div>

      <div class="common-form-item">
        <label class="common-search-label">状态</label>
        <div class="common-search-conrol">
          <nz-select
            nzAllowClear
            nzPlaceHolder="请选择"
            [(ngModel)]="seachParams.status"
          >
            <nz-option nzLabel="禁用" [nzValue]="0"></nz-option>
            <nz-option nzLabel="启用" [nzValue]="1"></nz-option>
          </nz-select>
        </div>
      </div>

      <div class="common-form-item">
        <label class="common-search-label">更新时间</label>
        <div class="common-search-conrol">
          <nz-range-picker
            [(ngModel)]="updateTimes"
            (ngModelChange)="timeChange($event)">
          </nz-range-picker>
        </div>
      </div>

      <div class="common-form-item">
        <button nz-button nzType="primary" class="m-r-8" (click)="seachData()">查询</button>
        <button nz-button nzType="default" (click)="resetData()">重置</button>
        <!-- <button nz-button nzType="link" (click)="isCollapse = !isCollapse">
          {{ isCollapse ? '收起' : '展开' }}<i nz-icon [nzType]="isCollapse ? 'up' : 'down'" nzTheme="outline"></i>
        </button> -->
      </div>
    </div>
  </div>
</nz-card>

<nz-card>
  <div class="opera-wrap p-b-10">
    <button nz-button nzType="primary" (click)="showModal(0)">
      <i nz-icon nzType="plus" nzTheme="outline"></i>新增机型
    </button>
  </div>

  <!-- Table -->
  <div class="pagination-wrap-position">
    <div class="table-wrap">
      <nz-table
        #basicTable
        nzSize="small"
        nzShowSizeChanger
        nzShowQuickJumper
        nzOuterBordered
        [nzFrontPagination]="false"
        [nzLoadingDelay]="100"
        [nzLoading]="tableParams.tableLoading"
        [nzData]="tableData"
        [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
        [nzTotal]="tableParams.total"
        [nzPageIndex]="tableParams.page"
        [nzPageSize]="tableParams.pageSize"
        [nzShowTotal]="totalTemplate"
        (nzPageIndexChange)="onPageIndexChange($event)"
        (nzPageSizeChange)="onPageSizeChange($event)"
      >
        <thead>
        <tr>
          <th nzAlign="center" nzWidth="120px">ID</th>
          <th nzAlign="center">机型名称</th>
          <th nzAlign="center">机型别名</th>
          <th nzAlign="center">机型图片</th>
          <th nzAlign="center">所属品类</th>
          <th nzAlign="center">所属系列</th>
          <th nzAlign="center">所属品牌</th>
          <th nzAlign="center">更新时间</th>
          <th nzAlign="center">状态</th>
          <th nzAlign="center">操作</th>
        </tr>
        </thead>

        <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- ID -->
          <td nzAlign="center">{{ data.id }}</td>
          <!-- 机型名称 -->
          <td nzAlign="center">{{ data.name || '-' }}</td>
          <!-- 机型别名 -->
          <td nzAlign="center">{{ data.alias || '-' }}</td>
          <!-- 机型图片 -->
          <td nzAlign="center">
            <img nz-image width="40px" height="40px" [nzSrc]="data.url" [nzFallback]="fallback"/>
          </td>
          <!-- 所属品类 -->
          <td nzAlign="center">{{ data.category === 1 ? '手机' : '平板' }}</td>
          <!-- 所属系列 -->
          <td nzAlign="center">{{ data.seriesName || '-' }}</td>
          <!-- 所属品牌 -->
          <td nzAlign="center">{{ data.brandName || '-' }}</td>
          <!-- 更新时间 -->
          <td nzAlign="center">{{ data.updateTime || '-' }}</td>
          <!-- 状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{color: data.status === 0 ? '#F56C6C' : '#27D525'}">
              {{ data.status === 0 ? '禁用' : '启用' || '-' }}
            </span>
          </td>
          <!-- 操作 -->
          <td nzAlign="center">
            <button nz-button nzType="link" (click)="showModal(1, data)">编辑</button>

            <a style="color: #F56C6C" (click)="changeStatus(data.id,0)" *ngIf="data['status']===1">禁用</a>
            <a style="color: #27D525" (click)="changeStatus(data.id,1)" *ngIf="data['status']===0">启用</a>
            <a
              nz-button
              nzType="link"
              nzDanger
              nz-popconfirm
              nzPopconfirmTitle="确认删除?"
              [nzIcon]="iconTpl"
              (nzOnConfirm)="changeStatus(data.id,2)">
              删除
            </a>
            <ng-template #iconTpl>
              <i nz-icon nzType="question-circle-o" style="color: red;"></i>
            </ng-template>
          </td>
        </tr>
        </tbody>
      </nz-table>

      <!-- 分页template -->
      <ng-template #totalTemplate let-total>共有 {{ tableParams.total }} 条</ng-template>
    </div>
  </div>
</nz-card>

<!-- 新增编辑 Modal START -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isVisible"
  [nzTitle]="modalType == 0 ? '新增机型' : '编辑机型'"
  (nzOnCancel)="handleCancel()">

  <div *nzModalContent>
    <div class="custom-model-body">
      <!-- body START -->
      <form nz-form class="modal-body" [formGroup]="validateForm">
        <nz-form-item>
          <nz-form-label nzSpan="6" nzRequired>机型名称</nz-form-label>
          <nz-form-control nzSpan="18" nzErrorTip="请输入机型名称!">
            <input formControlName="name" nz-input placeholder="请输入机型名称"/>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label nzSpan="6">机型别名</nz-form-label>
          <nz-form-control nzSpan="18">
            <input formControlName="alias" nz-input placeholder="请输入机型别名"/>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label nzSpan="6" nzRequired>所属品牌</nz-form-label>
          <nz-form-control nzSpan="18" nzErrorTip="请选择所属品牌!">
            <nz-select
              formControlName="brandId"
              (nzScrollToBottom)="loadMore(0)"
              nzPlaceHolder="请选择所属品牌"
              nzAllowClear
              nzShowSearch
              [nzDisabled]="modalItem.isDelete == 1"
              [nzDropdownRender]="renderTemplate"
              (ngModelChange)="brandChange($event)"
            >
              <nz-option *ngFor="let option of brandOptions" [nzValue]="option.id" [nzLabel]="option.name"></nz-option>
            </nz-select>
            <ng-template #renderTemplate>
              <nz-spin *ngIf="baradListForm.isLoading"></nz-spin>
            </ng-template>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label nzSpan="6" nzRequired>所属系列</nz-form-label>
          <nz-form-control nzSpan="18" nzErrorTip="请选择所属系列!">
            <nz-select
              formControlName="seriesId"
              nzPlaceHolder="请选择所属系列"
              nzAllowClear
              nzShowSearch
              [nzDisabled]="modalItem.isDelete == 1 || !validateForm.value.brandId"
            >
              <nz-option *ngFor="let option of modalSeriesOptions" [nzValue]="option.id"
                         [nzLabel]="option.name"></nz-option>
            </nz-select>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label nzSpan="6">图片</nz-form-label>
          <nz-form-control nzSpan="18" nzErrorTip="请选择图片">
            <nz-upload
              class="upload-img-box"
              nzAccept="image/*"
              nzAction=""
              nzListType="picture-card"
              (nzChange)="onModalPreview($event)"
              [nzShowUploadList]="false">
              <div ngDefaultControl formControlName="url">
                <ng-container *ngIf="!validateForm.value.url">
                  <i class="upload-icon" nz-icon [nzType]="uploadLoading ? 'loading' : 'plus'"></i>
                </ng-container>
                <img *ngIf="validateForm.value.url" [src]="validateForm.value.url" style="width: 100%"/>
              </div>
            </nz-upload>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label nzSpan="6">存储容量</nz-form-label>
          <nz-form-control nzSpan="18" nzErrorTip="请添加存储容量">
            <div ngDefaultControl formControlName="memory">
              <app-tags-add [(tagLists)]="capacityColorObjs.capacityArr"
                            (tagListsChange)="tagchange($event, 'memory')"></app-tags-add>
            </div>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label nzSpan="6">颜色</nz-form-label>
          <nz-form-control nzSpan="18" nzErrorTip="请添加颜色">
            <div ngDefaultControl formControlName="color">
              <app-tags-add [tagLists]="capacityColorObjs.colorArrs"
                            (tagListsChange)="tagchange($event, 'color')"></app-tags-add>
            </div>
          </nz-form-control>
        </nz-form-item>

        <nz-form-item>
          <nz-form-label nzSpan="6" nzRequired>状态</nz-form-label>
          <nz-form-control nzSpan="18" nzErrorTip="请选择状态!">
            <nz-radio-group formControlName="status">
              <label nz-radio [nzValue]="1">启用</label>
              <label nz-radio [nzValue]="0">禁用</label>
            </nz-radio-group>
          </nz-form-control>
        </nz-form-item>
      </form>
      <!-- body END -->
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="primary" [nzLoading]="subModalLoding" (click)="submitForm()">确定</button>
        <button nz-button nzType="default" (click)="handleCancel()">取消</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- 新增编辑 Modal END -->
